<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>评论API测试</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>统一评论API测试</h1>
    
    <div>
        <h2>测试添加评论</h2>
        <button onclick="testAddComment()">添加测试评论</button>
        <div id="addResult"></div>
    </div>
    
    <div>
        <h2>测试获取评论</h2>
        <button onclick="testGetComments()">获取器械评论</button>
        <div id="getResult"></div>
    </div>
    
    <div>
        <h2>测试获取评论数量</h2>
        <button onclick="testGetCommentCount()">获取评论数量</button>
        <div id="countResult"></div>
    </div>

    <script>
        const BASE_URL = 'http://localhost:8080';
        
        async function testAddComment() {
            try {
                const response = await axios.post(`${BASE_URL}/api/comments`, {
                    targetId: 1,
                    targetType: 1,
                    content: '这是一个测试评论',
                    userId: 1
                });
                
                document.getElementById('addResult').innerHTML = 
                    `<pre>${JSON.stringify(response.data, null, 2)}</pre>`;
            } catch (error) {
                document.getElementById('addResult').innerHTML = 
                    `<pre>错误: ${error.message}</pre>`;
            }
        }
        
        async function testGetComments() {
            try {
                const response = await axios.get(`${BASE_URL}/api/comments/target/1/1`);
                
                document.getElementById('getResult').innerHTML = 
                    `<pre>${JSON.stringify(response.data, null, 2)}</pre>`;
            } catch (error) {
                document.getElementById('getResult').innerHTML = 
                    `<pre>错误: ${error.message}</pre>`;
            }
        }
        
        async function testGetCommentCount() {
            try {
                const response = await axios.get(`${BASE_URL}/api/comments/count/1/1`);
                
                document.getElementById('countResult').innerHTML = 
                    `<pre>${JSON.stringify(response.data, null, 2)}</pre>`;
            } catch (error) {
                document.getElementById('countResult').innerHTML = 
                    `<pre>错误: ${error.message}</pre>`;
            }
        }
    </script>
    
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        
        div {
            margin-bottom: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
        }
        
        button:hover {
            background-color: #0056b3;
        }
        
        pre {
            background-color: #f8f9fa;
            padding: 10px;
            border-radius: 5px;
            overflow-x: auto;
        }
    </style>
</body>
</html>
